<template>
<div>数据变量内存</div>
</template>
<script>
var person = {
    name:"lxy",
    age:21,
    setName:function(name){
        this.name = name; 
    },
    setAge:function(age){
        this.age = age;
    }
}
person.setName("lxy1");
person["setAge"] = 22;//通过字符串访问对象属性
// console.log(person.setName);
// console.log(person.name," , ",person["age"]);
person.sex = "女";
person["content-type"] = "text/json"; //-@/属性名包含特殊字符，需要用字符串访问
// console.log(person.sex);
// console.log(person["content-type"]);

var names = ["lxy11","lxy21","lxy31"];

for(var i = 0; i<names.length; i++){
    if(i == 2){
        person[names[i]] = "ok"; //给对象动态添加属性
        // console.log(person[names[i]]);
        break;
    }
}

var tempName = "lxy22";
var msg = "hello1";
person.tempName = msg; //给对象动态添加属性
// console.log(person.tempName);//person["lxy22"] = undefined
person[tempName] = msg; //给对象动态添加属性
console.log(person["lxy22"]);
</script>
